//
//  ComposeViewController.swift
//  SinaWeibo
//
//  Created by NeXTSTEP on 15/10/4.
//  Copyright © 2015年 NeXTSTEP. All rights reserved.
//

import UIKit

class ComposeViewController: BaseViewController,UITextViewDelegate{

    @IBOutlet weak var toolBarBottom: NSLayoutConstraint!
    @IBOutlet weak var textView: UITextView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardChangeFrame:", name: UIKeyboardWillChangeFrameNotification, object: nil)
    }
    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    
    
    
    @IBOutlet weak var sendBarbutton: UIBarButtonItem!
    
    @IBAction func send(sender: AnyObject) {
        
    }
    
    @IBAction func close(sender: AnyObject) {
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    
    func keyboardChangeFrame(n: NSNotification){
        print(n)
        let rect = (n.userInfo!["UIKeyboardFrameEndUserInfoKey"] as! NSValue).CGRectValue()
        let duration = n.userInfo!["UIKeyboardAnimationDurationUserInfoKey"] as! NSTimeInterval
        
        let endY = self.view.frame.height - rect.origin.y
        UIView.animateWithDuration(duration) { () -> Void in
            self.toolBarBottom.constant = endY
            
            self.view.layoutIfNeeded()
        }
    }
    
    func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
        textView.resignFirstResponder()
    }
    
    
    
}
